package com.das.mechanic_base.adapter.groundpush;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.app.X3Constent;
import com.das.mechanic_base.bean.main.GiftBalanceBean;
import com.das.mechanic_base.utils.SpHelper;

import java.util.ArrayList;
import java.util.List;

public class X3SelectGiftSubmitAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;

    private List<GiftBalanceBean.CreditPresentVoListBean> mList;
    /**
     * 空数据时，显示空布局类型
     */
    private final int EMPTY_VIEW = 1;
    /**
     * 控制空布局的显隐
     */
    private int mEmptyType = 0;

    private String moneyUnit;

    public X3SelectGiftSubmitAdapter(Context mContext) {
        this.mContext = mContext;
        mList = new ArrayList<>();

        moneyUnit = (String) SpHelper.getData(X3Constent.MONEYCODE, "£");
    }

    public void changeData(List<GiftBalanceBean.CreditPresentVoListBean> littleAssistantBean, int isSelectMoneys) {
        this.mList = littleAssistantBean;
        moneyUnit = (String) SpHelper.getData(X3Constent.MONEYCODE, "£");
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new AssistantHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_adapter_gift_submit, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        AssistantHolder holder1 = (AssistantHolder) holder;
        GiftBalanceBean.CreditPresentVoListBean homeGetIMBean = mList.get(position);
        holder1.visit_name_tv.setText(homeGetIMBean.getOperatorName() + " " + String.format(mContext.getString(R.string.x3_top_up_money),homeGetIMBean.getPresentMoney() + "",moneyUnit));
        holder1.visit_date_tv.setText(homeGetIMBean.getPeriodDesc());
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public int getItemViewType(int position) {
        if (mEmptyType == EMPTY_VIEW) {
            //空布局的类型
            return EMPTY_VIEW;
        }
        return super.getItemViewType(position);
    }

    class AssistantHolder extends RecyclerView.ViewHolder {
        private TextView visit_name_tv;
        private TextView visit_date_tv;

        public AssistantHolder(@NonNull View itemView) {
            super(itemView);
            visit_date_tv = itemView.findViewById(R.id.visit_date_tv);
            visit_name_tv = itemView.findViewById(R.id.visit_name_tv);
        }
    }
}